[−][src]Crate cita_trie
Usage
use std::sync::Arc; use cita_trie::MemoryDB; use cita_trie::{PatriciaTrie, Trie}; use cita_trie::Keccak256Hash; fn main() { let memdb = Arc::new(MemoryDB::new(true)); let key = "test-key".as_bytes(); let value = "test-value".as_bytes(); let root = { let mut trie = PatriciaTrie::<_, Keccak256Hash>::new(Arc::clone(&memdb)); trie.insert(key.to_vec(), value.to_vec()).unwrap(); let v = trie.get(key).unwrap(); assert_eq!(Some(value.to_vec()), v); trie.root().unwrap() }; let mut trie = PatriciaTrie::<_, Keccak256Hash>::from(Arc::clone(&memdb), &root).unwrap(); let exists = trie.contains(key).unwrap(); assert_eq!(exists, true); let removed = trie.remove(key).unwrap(); assert_eq!(removed, true); let new_root = trie.root().unwrap(); println!("new root = {:?}", new_root); }
Structs
Keccak256Hash | |
MemoryDB | |
PatriciaTrie |
Enums
MemDBError | |
TrieError |
Traits
DB | "DB" defines the "trait" of trie and database interaction. You should first write the data to the cache and write the data to the database in bulk after the end of a set of operations. |
Hasher | |
Trie |